package springboot.app.conf;

import java.sql.SQLException ;

import javax.sql.DataSource ;

import org.springframework.beans.factory.annotation.Qualifier ;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder ;
import org.springframework.boot.context.properties.ConfigurationProperties ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Configuration ;
import org.springframework.context.annotation.Primary ;

/**
 * 装配自己的DataSource
 * @author 80002165 @date 2017年7月7日 下午5:48:55
 */
@Configuration
public class DataSourceConfig {
    
    
    @Bean(value="dataSource")
    @Qualifier("dataSource")
    @Primary
    @ConfigurationProperties(prefix="spring.datasource")
    public DataSource createDefDataSource() throws SQLException {
        return DataSourceBuilder.create().build() ;
    }
    
    
    @Bean(value="primaryDataSource")
    @Qualifier("primaryDataSource")
    @ConfigurationProperties(prefix="spring.datasource")
    public DataSource createDataSource() throws SQLException {
        return DataSourceBuilder.create().build() ;
    }
    
    @Bean(name = "secondaryDataSource")
    @Qualifier("secondaryDataSource")
    @ConfigurationProperties(prefix="spring.datasource")
    public DataSource secondaryDataSource() {
        return DataSourceBuilder.create().build();
    }
}
